package com.maven.front.controller.manageComment;

import com.maven.front.bean.EduComment;
import com.maven.front.bean.EduUser;
import com.maven.front.bean.Result;
import com.maven.front.dto.EduCommentDto;
import com.maven.front.service.manageComments.EduCommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("admin/comm")
@RestController
public class EduCommentController {


    @Autowired
    private EduCommentService eduCommentService;


    @GetMapping("list")
    public Result list(EduComment eduComment){
       // eduComment.setpCommentId(0);
        List<EduCommentDto> list=eduCommentService.list(eduComment);

        if (CollectionUtils.isEmpty(list)) {
            return new Result(1005, "查询失败");
        } else {
            return new Result(200,"查询成功",list);
        }

    }

    @GetMapping("init")
    public Result getById( int id){
        EduComment eduComment=this.eduCommentService.init(id);
        if(ObjectUtils.isEmpty(eduComment)){
            return new Result(10004,"查询失败");
        }else{
            return new Result(200,"成功",eduComment);
        }
    }

//    @GetMapping("getById")
//    public Result get( Integer pCommentId){
//        EduComment eduComment=this.eduCommentService.getById(pCommentId);
//        if(ObjectUtils.isEmpty(eduComment)){
//            return new Result(10004,"查询失败");
//        }else{
//            return new Result(200,"成功",eduComment);
//        }
//    }

    @PostMapping("update")
    public Result update(EduComment eduComment){
        int result=this.eduCommentService.update(eduComment);
        if(result>0){
            return new Result(200,"成功");
        }else{
            return new Result(10002,"修改失败");
        }
    }

    @PostMapping("delete")
    public Result delete( int id){
        int result=this.eduCommentService.delete(id);
        if(result>0){
            return new Result(200,"成功");
        }else{
            return new Result(10002,"删除失败");
        }
    }

    @GetMapping("selectkey")
    public Result selectKey(int id){
        EduUser eduUser=this.eduCommentService.selectkey(id);
        if(ObjectUtils.isEmpty(eduUser)){
            return new Result(10004,"查询失败");
        }else{
            return new Result(200,"成功",eduUser);
        }
    }

    @GetMapping("select")
   public  Result select(EduUser eduUser){

        List<EduUser> list=eduCommentService.select(eduUser);

        if (CollectionUtils.isEmpty(list)) {
            return new Result(10005, "查询失败");
        } else {
            return new Result(200,"查询成功",list);
        }
    }
}
